const base_url = "http://xjj0427.icu/wp-json/wp/v2/pod_yys/"
const androidId = device.getAndroidId()
const Path = "/sdcard/Pictures/" + androidId + "/" // 目录
const photoPath = Path + "yys/"
const w = device.width // 设备屏幕分辨率宽度
const h = device.height // 设备屏幕分辨率高度
const tail = "       -------Utils:"
// 504242927    --密钥
const API_Key = "LGZTmkf9AwP78E01jiYpmDyM"
const Secret_Key = "WGOi6d3tQvtB2B95XZCe2zeEnL5E1rtO"

files.ensureDir(photoPath)

Array.prototype.remove = function (val) {
	var index = this.indexOf(val)
	if (index > -1) {
		this.splice(index, 1)
	}
}

/**
 * @description 初始化
 * @param {Boolean}
 */
const init = () => {
	// //安卓版本高于Android 9
	if (device.sdkInt >= 28) {
		//等待截屏权限申请并同意
		threads.start(() => {
			packageName("com.android.systemui").text("立即开始").waitFor()
			text("立即开始").click()
		})
	}
	//申请截屏权限
	if (!requestScreenCapture()) {
		toast("请求截图失败")
		exit()
	}
}

/**
 * 设置百度Ocr api 、 secret
 */
const set_baiduOrc_key = () => {
	var storge = storages.create("yys")
	storge.put("bd_api_key", "LGZTmkf9AwP78E01jiYpmDyM")
	storge.put("bd_secret_key", "WGOi6d3tQvtB2B95XZCe2zeEnL5E1rtO")
}

/**
 * @description 获取百度AI识别token
 * @return {String}
 */
const get_baidu_access_Token = () => {
	var storage = storages.create("yys")
	var client_id = storage.get("bd_api_key") || API_Key
	var client_secret = storage.get("bd_secret_key") || Secret_Key
	var post_url = "https://aip.baidubce.com/oauth/2.0/token"
	var token_Res = http.post(post_url, {
		grant_type: "client_credentials",
		client_id: client_id,
		client_secret: client_secret,
	})
	var access_token = token_Res.body.json().access_token
	return access_token
}

/**
 * @description 获取百度识别源数据
 * @param {String} level
 * @return {String}
 */
const getBaiduWords = (level) => {
	try {
		shell("screencap -p " + Path + "screen.png", true)
	} catch (e) {
		e.javaException instanceof
		com.stardust.autojs.runtime.exception.ScriptInterruptedException
			? captureScreen(Path + "screen.png")
			: ""
	}
	var img = images.read(Path + "screen.png")
	var image = images.toBase64(img, "png", 100)
	switch (level) {
		case "high_position":
			SiteInfo_ocr_Url =
				"https://aip.baidubce.com/rest/2.0/ocr/v1/accurate"
			break
		case "normal_position":
			SiteInfo_ocr_Url =
				"https://aip.baidubce.com/rest/2.0/ocr/v1/general"
			break
		case "high":
			SiteInfo_ocr_Url =
				"https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic"
			break
		default:
			SiteInfo_ocr_Url =
				"https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic"
	}
	var access_token = get_baidu_access_Token()
	var ocr_Res = http.post(SiteInfo_ocr_Url, {
		headers: {
			"Content-Type": "application/x-www-form-urlencoded",
		},
		access_token: access_token,
		image: image,
		recognize_granularity: "small",
	})
	var str = ocr_Res.body.json().words_result || ocr_Res.body
	log(str)
	return str
}

/**
 * @description 百度AI判断是否包含一个目标词
 * @param {String} words
 * @param {String} level
 * @return {Boolean}
 */
const isContain = (words, level) => {
	var alive = false
	try {
		shell("screencap -p " + Path + "screen.png", true)
	} catch (e) {
		e.javaException instanceof
		com.stardust.autojs.runtime.exception.ScriptInterruptedException
			? captureScreen(Path + "screen.png")
			: ""
	}
	var img = images.read(Path + "screen.png")
	var image = images.toBase64(img, "png", 100)
	var SiteInfo_ocr_Url =
		level == "high"
			? "https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic"
			: "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic"
	var access_token = get_baidu_access_Token()
	var ocr_Res = http.post(SiteInfo_ocr_Url, {
		headers: {
			"Content-Type": "application/x-www-form-urlencoded",
		},
		access_token: access_token,
		image: image,
	})
	var json = ocr_Res.body.json().words_result
	json == undefined &&
		(log("Upper limit of times" + tail + "isContain"), exit())
	for (let item of json) {
		if (item.words.indexOf(words) != -1) {
			alive = true
			break
		}
	}
	return alive
}

/**
 * @description 百度AI判断是否包含多个目标词
 * @param {Array} words_arr
 * @param {String} level
 * @return {Boolean}
 */
const isContains = (words_arr, level) => {
	typeof words_arr == "object" && words_arr.length > 0
		? ""
		: (log("Parameter error"), exit())
	var alive = false
	try {
		shell("screencap -p " + Path + "screen.png", true)
	} catch (e) {
		e.javaException instanceof
		com.stardust.autojs.runtime.exception.ScriptInterruptedException
			? captureScreen(Path + "screen.png")
			: ""
	}
	var img = images.read(Path + "screen.png")
	var image = images.toBase64(img, "png", 100)
	var SiteInfo_ocr_Url =
		level == "high"
			? "https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic"
			: "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic"
	var access_token = get_baidu_access_Token()
	var ocr_Res = http.post(SiteInfo_ocr_Url, {
		headers: {
			"Content-Type": "application/x-www-form-urlencoded",
		},
		access_token: access_token,
		image: image,
	})
	var json = ocr_Res.body.json().words_result
	json == undefined &&
		(log("Upper limit of times" + tail + "isContains"), exit())
	for (let word_item of words_arr) {
		for (let item of json) {
			if (item.words.indexOf(word_item) != -1) {
				alive = true
				return alive
			}
		}
	}
	return alive
}

/**
 * @description 获取单个目标字的坐标
 * @param {String} words
 * @param {String} word
 * @param {String} level
 * @return {JSON}
 */
const getWordsPosition = (words, word, level) => {
	var posi = { x: "-1" }
	try {
		shell("screencap -p " + Path + "screen.png", true)
	} catch (e) {
		e.javaException instanceof
		com.stardust.autojs.runtime.exception.ScriptInterruptedException
			? captureScreen(Path + "screen.png")
			: ""
	}
	var img = images.read(Path + "screen.png")
	var image = images.toBase64(img, "png", 100)
	var SiteInfo_ocr_Url =
		level === "high"
			? "https://aip.baidubce.com/rest/2.0/ocr/v1/accurate"
			: "https://aip.baidubce.com/rest/2.0/ocr/v1/general"
	var access_token = get_baidu_access_Token()
	var ocr_Res = http.post(SiteInfo_ocr_Url, {
		headers: {
			"Content-Type": "application/x-www-form-urlencoded", //连接的请求方式,一般是'content-type': 'application/json',
		},
		access_token: access_token,
		image: image,
		recognize_granularity: "small",
	})
	var json = ocr_Res.body.json().words_result
	json == undefined &&
		(log("Upper limit of times" + tail + "getWordsPosition"), exit())
	for (let w of json) {
		if (w.words.indexOf(words) != -1) {
			let chars = w.chars
			for (let item of chars) {
				if (item.char == word) {
					let x = random(
						item.location.left,
						item.location.left + item.location.width
					)
					let y = random(
						item.location.top,
						item.location.top + item.location.height
					)
					posi = { x: x, y: y }
					break
				}
			}
			break
		}
	}
	return posi
}

/**
 * @description 获取单个目标字的所有坐标
 * @param {String} words
 * @param {String} level
 * @return {JSON}
 */
const getWordsAllPosition = (words, level, region) => {
	var posi_arr = [],
		posi = {}
	if (level && Array.isArray(level) && level.length === 4) region = level
	try {
		shell("screencap -p " + Path + "screen.png", true)
	} catch (e) {
		e.javaException instanceof
		com.stardust.autojs.runtime.exception.ScriptInterruptedException
			? captureScreen(Path + "screen.png")
			: ""
	}
	var img = images.read(Path + "screen.png")
	if (region && region.length === 4)
		img = images.clip(img, region[0], region[1], region[2], region[3])
	var image = images.toBase64(img, "png", 100)
	var SiteInfo_ocr_Url =
		level === "high"
			? "https://aip.baidubce.com/rest/2.0/ocr/v1/accurate"
			: "https://aip.baidubce.com/rest/2.0/ocr/v1/general"
	var access_token = get_baidu_access_Token()
	var ocr_Res = http.post(SiteInfo_ocr_Url, {
		headers: {
			"Content-Type": "application/x-www-form-urlencoded", //连接的请求方式,一般是'content-type': 'application/json',
		},
		access_token: access_token,
		image: image,
		recognize_granularity: "small",
	})
	var json = ocr_Res.body.json().words_result
	if (!json) {
		log("level: " + level)
		log("Upper limit of times" + tail + "getWordsAllPosition")
		return json
	}
	// json == undefined && (log('Upper limit of times' + tail + 'getWordsAllPosition'), exit())
	let index = random(0, words.length - 1)
	let one_word = words.substring(index, index + 1)
	json.forEach((w) => {
		if (w.words.indexOf(words) != -1) {
			let chars = w.chars
			for (let item of chars) {
				if (item.char == one_word) {
					let x = random(
						item.location.left,
						item.location.left + item.location.width
					)
					let y = random(
						item.location.top,
						item.location.top + item.location.height
					)
					posi = { x: x, y: y }
					break
				}
			}
			posi_arr.push(posi)
		}
	})
	return posi_arr
}

/**
 * @description 获取所有目标字的坐标
 * @param {Array} wordArray
 * @param {String} level
 * @return {Array}
 */
const getAllPosition = (wordArray, level) => {
	var posi = { x: -1, y: -1, w: -1, h: -1 },
		posi_arr = []
	try {
		shell("screencap -p " + Path + "screen.png", true)
	} catch (e) {
		e.javaException instanceof
		com.stardust.autojs.runtime.exception.ScriptInterruptedException
			? captureScreen(Path + "screen.png")
			: ""
	}
	var img = images.read(Path + "screen.png")
	var image = images.toBase64(img, "png", 100)
	var SiteInfo_ocr_Url =
		level === "high"
			? "https://aip.baidubce.com/rest/2.0/ocr/v1/accurate"
			: "https://aip.baidubce.com/rest/2.0/ocr/v1/general"
	var access_token = get_baidu_access_Token()
	var ocr_Res = http.post(SiteInfo_ocr_Url, {
		headers: {
			"Content-Type": "application/x-www-form-urlencoded", //连接的请求方式,一般是'content-type': 'application/json',
		},
		access_token: access_token,
		image: image,
		recognize_granularity: "small",
	})
	var json = ocr_Res.body.json().words_result
	json == undefined &&
		(log("Upper limit of times" + tail + "getAllPosition"), exit())
	let temp_arr = []
	for (let itemObj of wordArray) {
		// 遍历每一个词组
		let temp = true
		json.forEach((w) => {
			if (w.words.indexOf(itemObj) != -1) {
				// 是否包含词组
				temp = false
				let chars = w.chars
				for (let i = 0; i < itemObj.length; i++) {
					let word = itemObj.substring(i, i + 1)
					for (let item of chars) {
						if (item.char == word) {
							let x = item.location.left
							let y = item.location.top
							let w = item.location.width
							let h = item.location.height
							posi = { x: x, y: y, w: w, h: h }
							break
						}
					}
					temp_arr.push(posi)
					posi = { x: -1, y: -1, w: -1, h: -1 }
				}
			}
		})
		if (temp) {
			posi = { x: -1, y: -1, w: -1, h: -1 }
			for (let i = 0; i < itemObj.length; i++) {
				temp_arr.push(posi)
			}
		}
		posi_arr.push(temp_arr)
		temp_arr = []
	}
	return posi_arr
}

/**
 * @description 获取本地文件JSON
 * @param {String} path 文件路径
 * @return {JSON}
 */
const getPathJson = (path) => {
	var jsonObj
	if (files.exists(path)) {
		let texts = files.read(path)
		try {
			texts != "" ? (jsonObj = JSON.parse(texts)) : ""
		} catch (e) {
			jsonObj = undefined
		}
	} else {
		log("文件不存在！")
	}
	return jsonObj
}

/**
 * @description 保存JSON到文件
 * @param {String} path
 * @param {JSON} json
 * @return {Boolean}
 */
const savePathJson = (path, json) => {
	let isSave = false
	if (files.ensureDir(path)) {
		let jsonStr = JSON.stringify(json)
		files.write(path, jsonStr)
		isSave = true
	}
	return isSave
}

/**
 * @description 滑动
 * @param {String} dire
 * @return {Booleann}
 */
const swipeTo = (dire) => {
	let isSwipe = false
	switch (dire) {
		case "ba":
			isSwipe = swipe(
				random(1, w - 1),
				random(h - 10, h - 1),
				random(1, w - 1),
				random(1, 10),
				random(700, 800)
			)
			break
		case "top":
			isSwipe = swipe(
				random((w / 9) * 2, (w / 9) * 7),
				random((h / 11) * 9, (h / 11) * 10),
				random((w / 9) * 2, (w / 9) * 7),
				random((h / 11) * 2, (h / 11) * 3),
				random(400, 500)
			)
			break
		case "bottom":
			isSwipe = swipe(
				random((w / 9) * 2, (w / 9) * 7),
				random((h / 11) * 2, (h / 11) * 3),
				random((w / 9) * 2, (w / 9) * 7),
				random((h / 11) * 9, (h / 11) * 10),
				random(400, 500)
			)
			break
		case "left":
			isSwipe = swipe(
				random((w / 11) * 9, (w / 11) * 10),
				random((h / 7) * 2, (h / 7) * 5),
				random(w / 11, (w / 11) * 2),
				random((h / 7) * 2, (h / 7) * 5),
				random(500, 600)
			)
			break
		default:
			isSwipe = swipe(
				random(w / 11, (w / 11) * 2),
				random((h / 7) * 2, (h / 7) * 5),
				random((w / 11) * 9, (w / 11) * 10),
				random((h / 7) * 2, (h / 7) * 5),
				random(500, 600)
			)
	}
	return isSwipe
}

/**
 * @description 平滑滑动
 * @param {String} dire
 * @return {Booleann}
 */
const SwipeTo = (dire) => {
	let isSwipe = false
	switch (dire) {
		case "top":
			isSwipe = Swipe(
				random(1, w - 1),
				random((h / 11) * 9, (h / 11) * 10),
				random(1, w - 1),
				random(h / 10, (h / 10) * 2),
				random(100, 200)
			)
			break
		default:
			isSwipe = Swipe(
				random(1, w - 1),
				random(h / 10, (h / 10) * 2),
				random(1, w - 1),
				random((h / 11) * 10, h - 1),
				random(100, 200)
			)
	}
	return isSwipe
}

/**
 * @description 向上滑动(贴吧刷贴专用)
 */
const baSwipeUp = () => {
	let isSwipe = false
	isSwipe = swipe(
		random((w / 9) * 2, (w / 9) * 7),
		random((h / 11) * 9, (h / 11) * 10),
		random((w / 9) * 2, (w / 9) * 7),
		random(1, 10),
		random(400, 500)
	)
	return isSwipe
}

/**
 * @description 贴子中随意上下滑动
 * @param {String} dire
 * @returns {Boolean}
 */
const tieBaRanSwipe = (dire) => {
	let isSwipe = false
	isSwipe =
		dire == "down"
			? Swipe(
					random(w / 10, (w / 10) * 9),
					random(0.17 * h, 0.2 * h),
					random(w / 10, (w / 10) * 9),
					random((h / 10) * 9, (h / 10) * 8),
					random(50, 300)
			  )
			: Swipe(
					random(w / 10, (w / 10) * 9),
					random((h / 10) * 9, (h / 10) * 8),
					random(w / 10, (w / 10) * 9),
					random(0.17 * h, 0.2 * h),
					random(150, 300)
			  )
}

/**
 * @description 截取字符串中随机的一个字符
 * @param {String} str
 * @return {String}
 */
const getRanWord = (str) => {
	if (str.length > 0) {
		let num = random(1, str.length)
		let word = str.substring(num - 1, num)
		return word
	} else {
		log("字符为空")
	}
}

/**
 * @description 获取文本文件随机行字符
 * @param {String} path
 */
const getWaterWords = (path) => {
	if (files.exists(path)) {
		let textObj = open(path)
		let textArr = textObj.readlines()
		return textArr[random(0, textArr.length - 1)]
	} else {
		log("文本不存在！")
		exit()
	}
}

/**
 * @description 检测应用是否未响应
 * @param {String} path
 */
const testAppResp = (path) => {
	threads.start(function () {
		while (true) {
			let UIObj = text("关闭应用").findOnce()
			if (UIObj != null) {
				log("应用无响应，关闭应用")
				UIObj.click()
				sleep(5000)
				launch(path)
			}
			sleep(15000)
		}
	})
}

/**
 * @description Get请求
 * @param {*} url
 */
// const getRequest = url => {
//     return new Promise((resolve,reject)=>{
//         let data = http.get(url)
//         data.statusCode===200? resolve(data.body.json()):reject(data.body.json())
//     })
// }
const getRequest = (url) => {
	return http.get(url, {
		headers: {
			"Accept-Language": "zh-cn,zh;q=0.5",
			"User-Agent":
				"Mozilla/5.0(Macintosh;IntelMacOSX10_7_0)AppleWebKit/535.11(KHTML,likeGecko)Chrome/17.0.963.56Safari/535.11",
		},
	})
}

/**
 * @description Post请求
 * @param {*} url
 * @param {*} data
 */
const postRequest = (url, data) => {
	return http.post(url, data)
}

/**
 * @description 比较两个日期的大小
 * @param {*} dateone
 * @param {*} datetwo
 */
const compare = (dateone, datetwo) => {
	let flag = dateone > datetwo ? true : false
	return flag
}

/**
 * @description 将字符串数组转化成单字符串数组
 * @param {*} arr
 */
function strArrToStrArr(arr) {
	let arr_new = []
	if (arr.length > 0)
		for (let item of arr)
			for (let i = 0; i < item.length; i++)
				arr_new.push(item.substring(i, i + 1))
	return arr_new
}

/**
 * @description 验证密钥是否过期
 * @param {*} pwd 密钥
 */
const isAlive = (pwd) => {
	let falg = false
	let id = uncompileStr(pwd)
	let request = getRequest(base_url + id)
	if (request.statusCode === 200) {
		let data = JSON.parse(request.body.string())
		let pod_due_date = data.pod_due_date
		let dateone = new Date(Date.parse(pod_due_date.replace(/-/g, "/")))
		falg = compare(dateone, new Date())
	}
	return falg
}

/**
 * @description 等待
 */
const sleeps = () => {
	sleep(random(3000, 5000))
}

/**
 * @description 等待计时并报时
 * @param {Number} second
 */
const waitTime = (second) => {
	log("需等待 " + second + " 秒")
	for (let i = 1; i <= second; i++) sleep(1000), log("已等待：" + i + "秒")
}

/**
 * @description 随机等待计时并报时
 * @param {Number} first
 * @param {Number} second
 */
const ranWaitTime = (first, second) => {
	let times = random(first, second)
	log("需等待 " + times + " 秒")
	for (let i = 1; i <= times; i++) sleep(1000), log("已等待: " + i + " 秒")
}

/**
 * @description 运行的时间
 * @param {Number} times
 */
const runTime = (times) => {
	threads.start(function () {
		log("运行时间：" + times + " 分钟")
		for (let i = 1; i <= times; i++) {
			sleep(60 * 1000)
			log("已运行 " + i + " 分钟")
		}
		exit()
	})
}

/**
 * @description 对字符串进行(硬核)加密
 * @param {*} code
 */
const compileStr = (code) => {
	return ((code * 427 - 10) * 328 - 10) * 328 - 1
}

/**
 * @description 对字符串进行(硬核)解密
 * @param {*} code
 */
const uncompileStr = (code) => {
	return (((Number(code) + 1) / 328 + 10) / 328 + 10) / 427
}

/**
 * @description 停止当前脚本的运行
 */
const stopJB = () => {
	engines.myEngine().forceStop()
}

/**
 * @description 查找图片(不主动截图)
 * @Param {String} pic
 * @Param {Array} region
 * @Param {Float} threshold
 */
const findPhoto = (pic, region, threshold) => {
	if (region) {
		if (typeof region == "number") {
			let temp = region
			region = threshold
			threshold = temp
		}
	}
	threshold = threshold || 0.9
	region = region || [0, 0]
	let screen = ""
	while (!screen) {
		screen = images.read(Path + "screen.png")
	}
	let suffix = /\.(jpg|jpeg|png|bmp)$/.test(pic) ? "" : ".png"
	let picObj = ""
	while (!picObj) {
		picObj = images.read(photoPath + pic + suffix)
	}
	let Point =
		findImage(screen, picObj, {
			region: region,
			threshold: threshold,
		}) || false
	if (Point) {
		let w = picObj.getWidth()
		let h = picObj.getHeight()
		Point.x = random(Point.x, Point.x + w)
		Point.y = random(Point.y, Point.y + h)
	}
	screen.recycle()
	picObj.recycle()
	return Point
}

/**
 * @description 查找图片并点击(不主动截图)
 */
const findPhotoTap = (pic, region, threshold) => {
	let flag = false
	let Point = findPhoto(pic, region, threshold)
	if (Point) {
		click(Point.x, Point.y)
		log(Point.x, Point.y)
		log(pic + ": 点击成功")
		flag = true
	}
	return flag
}

/**
 * @description 查找图片
 * @Param {String} pic
 * @Param {Array} region
 * @Param {Float} threshold
 */
const findPicture = (pic, region, threshold) => {
	if (region) {
		if (typeof region == "number") {
			let temp = region
			region = threshold
			threshold = temp
		}
	}
	threshold = threshold || 0.9
	region = region || [0, 0]
	try {
		shell("screencap -p " + Path + "screen.png", true)
	} catch (e) {
		captureScreen(Path + "screen.png")
	}
	let screen = ""
	while (!screen) {
		screen = images.read(Path + "screen.png")
	}
	let suffix = /\.(jpg|jpeg|png|bmp)$/.test(pic) ? "" : ".png"
	let picObj = ""
	while (!picObj) {
		picObj = images.read(photoPath + pic + suffix)
	}
	let Point =
		findImage(screen, picObj, {
			region: region,
			threshold: threshold,
		}) || false
	if (Point) {
		let w = picObj.getWidth()
		let h = picObj.getHeight()
		Point.x = random(Point.x, Point.x + w)
		Point.y = random(Point.y, Point.y + h)
	}
	screen.recycle()
	picObj.recycle()
	return Point
}

/**
 * @description 查找图片并点击
 */
const findPictureTap = (pic, region, threshold) => {
	let flag = false
	let Point = findPicture(pic, region, threshold)
	if (Point) {
		click(Point.x, Point.y)
		log(pic + ": 点击成功")
		flag = true
	}
	return flag
}

/**
 * @description 点击图片（相似度从 0.9 至 0.5）
 * @Param {String} pic_name 图片名称
 * @Param {Number} level 相似度
 */
const tapPicture = (pic_name, level) => {
	let find_level = level || 0.9
	let flag = false
	let do_flag = true
	while (do_flag) {
		sleep(1500)
		if (findPictureTap(pic_name, find_level)) {
			flag = true
			do_flag = false
		} else {
			if (find_level > 0.5) {
				find_level -= 0.1
				find_level = Number(find_level.toFixed(1))
			} else {
				do_flag = false
			}
		}
	}
	if (!flag) log("未找到图: " + pic_name)
	return flag
}

/**
 * @description 获取当前的日期时间 格式“yyyy-MM-dd HH:MM:SS”
 */
const getNowFormatDate = () => {
	var date = new Date()
	var seperator1 = "-"
	var seperator2 = "-"
	var month = date.getMonth() + 1
	var strDate = date.getDate()
	if (month >= 1 && month <= 9) {
		month = "0" + month
	}
	if (strDate >= 0 && strDate <= 9) {
		strDate = "0" + strDate
	}
	var currentdate =
		date.getFullYear() +
		seperator1 +
		month +
		seperator1 +
		strDate +
		"_" +
		date.getHours() +
		seperator2 +
		date.getMinutes() +
		seperator2 +
		date.getSeconds()
	return currentdate
}

/**
 * @description 截图
 */
const snapshots = () => {
	let type = "screen_shell_"
	let command = "screencap -p " + Path + type + getNowFormatDate() + ".png"
	try {
		shell(command, true)
		toastLog("shell 已截图")
	} catch (e) {
		init()
		sleep(1000)
		type = "screen_captureScreen_"
		command = Path + type + getNowFormatDate() + ".png"
		captureScreen(command)
		toastLog("已截图")
	}
  // init()
  // sleep(1000)
  // type = "screen_captureScreen_"
  // command = Path + type + getNowFormatDate() + ".png"
  // captureScreen(command)
  // toastLog("已截图")
}

/**
 * 截图
 * @param {*} str 截图命名前缀
 */
const screenshot = (str) => {
	captureScreen(Path + str + "screen_" + getNowFormatDate() + ".png")
}

/**
 * @description 点击两个坐标形成范围的随机坐标
 * @Param {Number} a 坐标一的横坐标
 * @Param {Number} b 坐标一的纵坐标
 * @Param {Number} m 坐标二的横坐标
 * @Param {Number} n 坐标二的纵坐标
 */
const tapRandom = (a, b, m, n) => {
	let x = a
	let y = b
	if (m && n) {
		x = random(a, m)
		y = random(b, n)
		log(x, y)
	}
	click(x, y)
}

module.exports = {
	Path: Path,
	init: init,
	stopJB: stopJB,
	compileStr: compileStr,
	uncompileStr: uncompileStr,
	getRequest: getRequest,
	postRequest: postRequest,
	compare: compare,
	isAlive: isAlive,
	runTime: runTime,
	sleeps: sleeps,
	waitTime: waitTime,
	ranWaitTime: ranWaitTime,
	strArrToStrArr: strArrToStrArr,
	set_baiduOrc_key: set_baiduOrc_key,
	getWordsAllPosition: getWordsAllPosition,
	getAllPosition: getAllPosition,
	getBaiduWords: getBaiduWords,
	getPathJson: getPathJson,
	savePathJson: savePathJson,
	getWordsPosition: getWordsPosition,
	isContain: isContain,
	isContains: isContains,
	swipeTo: swipeTo,
	SwipeTo: SwipeTo,
	getRanWord: getRanWord,
	getWaterWords: getWaterWords,
	testAppResp: testAppResp,
	baSwipeUp: baSwipeUp,
	tieBaRanSwipe: tieBaRanSwipe,
	findPicture: findPicture,
	findPictureTap: findPictureTap,
	tapPicture: tapPicture,
	getNowFormatDate: getNowFormatDate,
	snapshots: snapshots,
	tapRandom: tapRandom,
	screenshot: screenshot,
	findPhoto: findPhoto,
	findPhotoTap: findPhotoTap,
}
